(library (func-utils)
  (export compose id)
  (import
    (except (rnrs base) let-values)
    (only (guile) lambda* λ)
    (srfi srfi-1)))


(define id
  (λ (sth) sth))


(define compose
  (lambda* (. funcs)
    (cond
     [(null? funcs) id]
     [else
      (λ (arg)
        ;; apply this function to the result of ...
        ((first funcs)
         ;; .. the application of the composition of the
         ;; rest of the functions on the argument.
         ((apply compose (cdr funcs)) arg)))])))
